﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;

namespace BusinessLogic
{
    public abstract class BaseCommand<T> where T : class
    {
        public T Result { get; set; }

        public void Execute()
        {
            try
            {
                Command();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void ExecuteWithTransaction()
        {
            using (var ts = new TransactionScope())
            {
                try
                {
                    Command();
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                    throw ex;
                }

                ts.Complete();
            }
        }

        public abstract void Command();
    }
}
